<template>
  <div class="mod-crm__crmtask">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-button @click="state.getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="state.exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('crm:crmtask:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('crm:crmtask:delete')" type="danger" @click="state.deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="tskName" label="联络任务名字" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskTitle" label="联络任务标题" header-align="center" align="center"></el-table-column>
      <el-table-column prop="exhId" label="展会id" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskType" label="联络任务类型" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskTempPath" label="temp_path" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskGrade" label="grade" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskBDate" label="bdate" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskCreatorId" label="creatorId" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskModifierId" label="modifierId" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskCreateTime" label="创建时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskModifyTime" label="modifyTime" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskStufs" label="stufs" header-align="center" align="center"></el-table-column>
      <el-table-column prop="qtrId" label="qtrId" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskIfShare" label="是否存在替换" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskSource" label="source" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskSysState" label="syState" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskRemark" label="remark" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskFlag" label="flag" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskRxMail" label="rxMail" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskWizardFile" label="wizardFile" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskMailSender" label="mailSernder" header-align="center" align="center"></el-table-column>
      <el-table-column prop="ojaId" label="ojaId" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskIfAllowSkip" label="ifAllowSkip" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskIfConToPdf" label="ifConToPdf" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskAnnexFile" label="annexFile" header-align="center" align="center"></el-table-column>
      <el-table-column prop="creator" label="创建人" header-align="center" align="center"></el-table-column>
      <el-table-column prop="updater" label="更新人" header-align="center" align="center"></el-table-column>
      <el-table-column prop="tskUpdateTime" label="更新时间" header-align="center" align="center"></el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="state.hasPermission('crm:crmtask:update')" type="primary" link @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="state.hasPermission('crm:crmtask:delete')" type="primary" link @click="state.deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update :key="addKey" ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { nextTick, reactive, ref, toRefs, watch } from "vue";
import AddOrUpdate from "./crmtask-add-or-update.vue";

const view = reactive({
  getDataListURL: "/crm/crmtask/page",
  getDataListIsPage: true,
  exportURL: "/crm/crmtask/export",
  deleteURL: "/crm/crmtask",
  deleteIsBatch: true,
  dataForm: {
  }
});

const state = reactive({ ...useView(view), ...toRefs(view) });


const addKey = ref(0);
const addOrUpdateRef = ref();
const addOrUpdateHandle = (tskId?: number) => {
  addKey.value++;
  nextTick(() => {
    addOrUpdateRef.value.init(tskId);
  });
};
</script>